<?php

class HomeController extends Controller
{
    public function initialise()
    {    
    }
    
    public function main($args=null)
    {
        $dom = DataObjectManager::inst();
        $vm = ViewManager::inst();
        $db = DBConnection::inst();
        $proc = "NewsPostFetchAll";
        
        $proc2 = "TagFetchForNewsPost";
        
        if ($db->executeStoredProcedure($proc, Array(), $returnData)) {
            foreach ($returnData as $row) {
                $newsPost = $dom->fetchDataObject("NewsPost", $row["id"]);
                $newsPost->link();
                $tags = Array();
                if ($db->executeStoredProcedure($proc2, array($row["id"]), $returnData2))
                {
                    foreach ($returnData2 as $row)
                    {
                        $tags[] = $dom->fetchDataObject("Tag", $row["id"]);
                    }
                }
                $this->view = $vm->registerNewView("newspost");
                $this->view->registerVariable($newsPost, "newspost");
                $this->view->registerVariable($tags, "tags");
            }
        }
    }
}

?>
